﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using TTQT.TTQT_Code;

/// <summary>
/// Summary description for GioHang
/// </summary>
public class GioHang
{
    public ArrayList sanPhamList;
    public GioHang()
    {
        sanPhamList = new ArrayList();
    }
    public void muaThem(SanPhamInfo sp)
    {
        bool coRoi = false;
        try
        {
            foreach (SanPhamInfo itm in sanPhamList)
            {
                if(itm.isSanPham(sp))
                {
                    coRoi = true;
                    itm.SoLuongDatMua += sp.SoLuongDatMua;//Khong biet nó có cập nhật trong arrayList ko????
                }
            }
        }
        catch (Exception exxx)
        {
          
        }
        if(!coRoi)
        {
            sanPhamList.Add(sp);
        }
    }
    public void updateSoLuong(SanPhamInfo sp)
    {
        bool coRoi = false;
        try
        {
            foreach (SanPhamInfo itm in sanPhamList)
            {
                if (itm.isSanPham(sp))
                {
                    coRoi = true;
                    itm.SoLuongDatMua = sp.SoLuongDatMua;//Khong biet nó có cập nhật trong arrayList ko????
                }
            }
        }
        catch (Exception exxx)
        {

        }
        if (!coRoi)
        {
            sanPhamList.Add(sp);
        }
    }
    public void xoaBo(SanPhamInfo sp)
    {
        try
        {
            foreach (SanPhamInfo itm in sanPhamList)
            {
                if (itm.isSanPham(sp))
                {
                    sanPhamList.Remove(itm);
                }
            }
        }
        catch (Exception exx)
        {
            
        }
        
    }
    public void xoaHet()
    {
        sanPhamList=new ArrayList();
    }
    public string tongTien()
    {
        string kq = "";
        try
        {
            double soTien = 0;
            foreach (SanPhamInfo itm in sanPhamList)
            {
                soTien += itm.SoLuongDatMua*TTQTCommon.ToFloat(itm.GiaBanCoChietKhau, 0);
            }
            kq= TTQTCommon.formatTien_KhongThapPhan(soTien.ToString());
        }catch(Exception exx)
        {
            kq = "";
        }
        return kq;
    }
}
